<?php

class Pegawai1 extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('model_user');
        if ($this->model_user->auth() == 0 || $this->model_user->auth() !== 1) {
            redirect('login/index');
        } else {
            if ($this->session->userdata('type') == 'pegawai2') {
                redirect('pegawai2');
            } else if ($this->session->userdata('type') == 'boss') {
                redirect('boss');
            }
        }
        $this->load->model('model_barang');
        $this->load->library('pagination');
    }

    function index() {
        $data['nama'] = $this->session->userdata['nama'];
        $data['main_content'] = 'welcome';
        $this->load->view('includes/template', $data);
    }

    function barang() {
        $perpage = 10; //tentukan jumlah data per halaman
            //untuk konfigurasi pagination
            $segment = $this->uri->segment(3);
        //untuk konfigurasi pagination
        $config = array(
            'base_url' => base_url() . 'pegawai1/barang/',
            'total_rows' => $this->db->get('order')->num_rows(),
            'per_page' => $perpage,
            'num_links' => 10,
            'uri_segment' => 3,
            'full_tag_open' => '<div class="pagination pagination-centered paging"><ul>',
                'full_tag_close' => '</ul></div>',
                'num_tag_open' => '<li class="jawab">',
                'num_tag_close' => '</li>',
                'prev_tag_open' => '<li class="jawab">',
                'prev_tag_close' => '</li>',
                'next_tag_open' => '<li class="jawab">',
                'next_tag_close' => '</li>',
                'last_tag_open' => '<li>',
                'last_tag_close' => '</li>',
                'first_tag_open' => '<li>',
                'first_tag_close' => '</li>',
                'cur_tag_open' => '<li class="active"><span>',
                'cur_tag_close' => '</span></li>',
                'first_link' => false,
                'last_link' => false
        );    //inisialisasi pagination dn config di atas
        $this->pagination->initialize($config);
        $data['query'] = $this->model_barang->getAlls($perpage, $segment);
        $data['main_content'] = 'barang/inputan';
        //$data['query'] = $this->model_barang->getAll();
        $this->load->view('includes/template', $data);
    }

    function pengiriman() {
        $perpage = 10; //tentukan jumlah data per halaman
            //untuk konfigurasi pagination
            $segment = $this->uri->segment(3);
        //untuk konfigurasi pagination
        $config = array(
            'base_url' => base_url() . 'pegawai1/pengiriman/',
            'total_rows' => $this->db->get('order')->num_rows(),
            'per_page' => $perpage,
            'num_links' => 10,
            'uri_segment' => 3,
            'full_tag_open' => '<div class="pagination pagination-centered paging"><ul>',
                'full_tag_close' => '</ul></div>',
                'num_tag_open' => '<li class="jawab">',
                'num_tag_close' => '</li>',
                'prev_tag_open' => '<li class="jawab">',
                'prev_tag_close' => '</li>',
                'next_tag_open' => '<li class="jawab">',
                'next_tag_close' => '</li>',
                'last_tag_open' => '<li>',
                'last_tag_close' => '</li>',
                'first_tag_open' => '<li>',
                'first_tag_close' => '</li>',
                'cur_tag_open' => '<li class="active"><span>',
                'cur_tag_close' => '</span></li>',
                'first_link' => false,
                'last_link' => false
        );    //inisialisasi pagination dn config di atas
        $this->pagination->initialize($config);
        
        $data['main_content'] = 'pengiriman/inputan';
        $data['query'] = $this->model_barang->getAlls($perpage, $segment);
        $this->load->view('includes/template', $data);
    }

    function show() {
        $perpage = 10; //tentukan jumlah data per halaman
            //untuk konfigurasi pagination
            $segment = $this->uri->segment(3);
        //untuk konfigurasi pagination
        $config = array(
            'base_url' => base_url() . 'pegawai1/barang/',
            'total_rows' => $this->db->get('order')->num_rows(),
            'per_page' => $perpage,
            'num_links' => 10,
            'uri_segment' => 3,
            'full_tag_open' => '<div class="pagination pagination-centered paging"><ul>',
                'full_tag_close' => '</ul></div>',
                'num_tag_open' => '<li class="jawab">',
                'num_tag_close' => '</li>',
                'prev_tag_open' => '<li class="jawab">',
                'prev_tag_close' => '</li>',
                'next_tag_open' => '<li class="jawab">',
                'next_tag_close' => '</li>',
                'last_tag_open' => '<li>',
                'last_tag_close' => '</li>',
                'first_tag_open' => '<li>',
                'first_tag_close' => '</li>',
                'cur_tag_open' => '<li class="active"><span>',
                'cur_tag_close' => '</span></li>',
                'first_link' => false,
                'last_link' => false
        );    //inisialisasi pagination dn config di atas
        $this->pagination->initialize($config);
        $data['query'] = $this->model_barang->getAlls($perpage, $segment);
        $this->load->view('barang/show', $data);
    }
    
    function shows() {
        $perpage = 10; //tentukan jumlah data per halaman
            //untuk konfigurasi pagination
            $segment = $this->uri->segment(3);
        //untuk konfigurasi pagination
        $config = array(
            'base_url' => base_url() . 'pegawai1/pengiriman/',
            'total_rows' => $this->db->get('order')->num_rows(),
            'per_page' => $perpage,
            'num_links' => 10,
            'uri_segment' => 3,
            'full_tag_open' => '<div class="pagination pagination-centered paging"><ul>',
                'full_tag_close' => '</ul></div>',
                'num_tag_open' => '<li class="jawab">',
                'num_tag_close' => '</li>',
                'prev_tag_open' => '<li class="jawab">',
                'prev_tag_close' => '</li>',
                'next_tag_open' => '<li class="jawab">',
                'next_tag_close' => '</li>',
                'last_tag_open' => '<li>',
                'last_tag_close' => '</li>',
                'first_tag_open' => '<li>',
                'first_tag_close' => '</li>',
                'cur_tag_open' => '<li class="active"><span>',
                'cur_tag_close' => '</span></li>',
                'first_link' => false,
                'last_link' => false
        );    //inisialisasi pagination dn config di atas
        $this->pagination->initialize($config);
        $data['query'] = $this->model_barang->getAlls($perpage, $segment);
        $this->load->view('pengiriman/show', $data);
    }

    function submit() {
        if ($this->input->post('submit')) {

            if ($this->input->post('id')) {
                $this->form_validation->set_rules('job_order', 'Job Order', 'required');
//                $this->form_validation->set_rules('password', 'Password', 'matches[passconf]');
//                $this->form_validation->set_rules('nama', 'Nama', 'required|min_length[5]|max_length[25]');

                if ($this->form_validation->run() == FALSE) {
//                    $data['id'] = $this->input->post('id');
//                    $data['nip'] = set_value('nip');
//                    $data['nama'] = set_value('nama');
                    $this->load->view('barang/edit', $data);
                } else {
                    $this->model_barang->update();
                    echo "<script type='text/javascript'>window.top.window.alertz('alert-success','Sukses !', 'Data berhasil diupdate');</script>";
                    //redirect('guru/index');
                }
            } else {
                $this->form_validation->set_rules('job_order', 'Job Order', 'required');

                if ($this->form_validation->run() == FALSE) {
                    $data['query'] = $this->model_barang->getAll();
                    $this->load->view('barang/input', $data);
                } else {
                    if ($this->model_barang->save()) {
                        echo "<script type='text/javascript'>window.top.window.alertz('alert-success','Sukses !', 'Data berhasil dimasukkan');</script>";
                    } else {
                        echo "<script type='text/javascript'>window.top.window.alertz('alert-error','Gagal !', 'Data gagal masuk');</script>";
                    }
                }
            }
        }
    }

    function input() {
        $this->load->view('barang/input');
    }

    function edit() {
        $id = $this->uri->segment(3);
        $data['result'] = $this->model_barang->getBarang($id);

        if (empty($id) or count($data['result']) == 0) {
            redirect('admin/guru/index');
        } else {
            $result = $this->model_barang->getBarang($id);
            $data['id_order'] = $result['id_order'];
            $data['job_order'] = $result['job_order'];
            $data['no_sj'] = $result['no_sj'];
            $data['consgnee'] = $result['consgnee'];
            $data['origin'] = $result['origin'];
            $data['shipper'] = $result['shipper'];
            $data['via'] = $result['via'];
            $data['agent'] = $result['agent'];
            $data['ctn'] = $result['ctn'];
            $data['kg'] = $result['kg'];
            $data['m3'] = $result['m3'];
            $data['invoice'] = $result['invoice'];
            $data['description'] = $result['description'];
            $data['delivery'] = $result['delivery'];
            $data['penerimaan'] = $result['penerimaan'];
            $data['cost'] = $result['cost'];
            $data['profit'] = $result['profit'];
            $data['remarks'] = $result['remarks'];
            $this->load->view('barang/edit', $data);
        }
    }

    function delconf() {
        $id = $this->uri->segment(3);
        $data['result'] = $this->model_barang->getBarang($id);

        if (empty($id) or count($data['result']) == 0) {
            redirect('pegawai1/index');
        } else {
            $result = $this->model_barang->getBarang($id);
            $data['id_order'] = $result['id_order'];
            $data['job_order'] = $result['job_order'];
            $data['no_sj'] = $result['no_sj'];
            $data['consgnee'] = $result['consgnee'];
            $data['origin'] = $result['origin'];
            $data['shipper'] = $result['shipper'];
            $data['via'] = $result['via'];
            $data['agent'] = $result['agent'];
            $data['ctn'] = $result['ctn'];
            $data['kg'] = $result['kg'];
            $data['m3'] = $result['m3'];
            $data['invoice'] = $result['invoice'];
            $data['description'] = $result['description'];
            $data['delivery'] = $result['delivery'];
            $data['penerimaan'] = $result['penerimaan'];
            $data['cost'] = $result['cost'];
            $data['profit'] = $result['profit'];
            $data['remarks'] = $result['remarks'];
            $this->load->view('barang/del', $data);
        }
    }

    function edits() {
        $id = $this->uri->segment(3);
        $data['result'] = $this->model_barang->getBarang($id);

        if (empty($id) or count($data['result']) == 0) {
            redirect('admin/guru/index');
        } else {
            $result = $this->model_barang->getBarang($id);
            $data['id_order'] = $result['id_order'];
            $data['job_order'] = $result['job_order'];
            $data['no_sj'] = $result['no_sj'];
            $data['consgnee'] = $result['consgnee'];
            $data['origin'] = $result['origin'];
            $data['shipper'] = $result['shipper'];
            $data['via'] = $result['via'];
            $data['agent'] = $result['agent'];
            $data['ctn'] = $result['ctn'];
            $data['kg'] = $result['kg'];
            $data['m3'] = $result['m3'];
            $data['invoice'] = $result['invoice'];
            $data['description'] = $result['description'];
            $data['delivery'] = $result['delivery'];
            $data['penerimaan'] = $result['penerimaan'];
            $data['cost'] = $result['cost'];
            $data['profit'] = $result['profit'];
            $data['remarks'] = $result['remarks'];
            $data['etd_sin'] = $result['etd_sin'];
            $data['eta_jkt'] = $result['eta_jkt'];
            $this->load->view('pengiriman/edit', $data);
        }
    }

    function delete($id) {
        $this->db->delete('order', array('id_order' => $id));
        echo "<script type='text/javascript'>window.top.window.alertz('alert-success','Sukses !', 'Data berhasil dihapus');</script>";
        //$this->load->view('admin/view_guru/show', $data);
    }

    function submitpengiriman() {
        if ($this->input->post('submit')) {
            $this->form_validation->set_rules('job_order', 'Job Order', 'required');
//                $this->form_validation->set_rules('password', 'Password', 'matches[passconf]');
//                $this->form_validation->set_rules('nama', 'Nama', 'required|min_length[5]|max_length[25]');

            if ($this->form_validation->run() == FALSE) {
                echo "<script type='text/javascript'>window.top.window.alertz('alert-error','Gagal !', 'Data gagal masuk');</script>";
            } else {
                $this->model_barang->updates();
                echo "<script type='text/javascript'>window.top.window.alertz('alert-success','Sukses !', 'Data berhasil diupdate');</script>";
                //redirect('guru/index');
            }
        }
    }

    function setting() {
        $data['row'] = $this->model_user->fetch_single($this->session->userdata('id'));
        $this->load->view('setting', $data);
    }

    function update_set() {
        if ($this->model_user->update_set()) {
            echo "<script type='text/javascript'>window.top.window.alertu('Setting berhasil diupdate');</script>";
        } else {
            echo "<script type='text/javascript'>window.top.window.alertu('Setting gagal diupdate');</script>";
        }
    } 
    
    function cek_order(){
        $q = $this->input->post('q');
        echo $this->model_barang->cek_order($q);
    }
    
    function cetak() {
        $id = $this->uri->segment(3);
        $data['result'] = $this->model_barang->getBarang($id);

        if (empty($id) or count($data['result']) == 0) {
            redirect('admin/guru/index');
        } else {
            $result = $this->model_barang->getBarang($id);
            $data['id_order'] = $result['id_order'];
            $data['job_order'] = $result['job_order'];
            $data['no_sj'] = $result['no_sj'];
            $data['consgnee'] = $result['consgnee'];
            $data['origin'] = $result['origin'];
            $data['shipper'] = $result['shipper'];
            $data['via'] = $result['via'];
            $data['agent'] = $result['agent'];
            $data['ctn'] = $result['ctn'];
            $data['kg'] = $result['kg'];
            $data['m3'] = $result['m3'];
            $data['invoice'] = $result['invoice'];
            $data['description'] = $result['description'];
            $data['delivery'] = $result['delivery'];
            $data['penerimaan'] = $result['penerimaan'];
            $data['cost'] = $result['cost'];
            $data['profit'] = $result['profit'];
            $data['remarks'] = $result['remarks'];
            $this->load->view('barang/cetak', $data);
        }
    }
    
    function search(){
        $q = $this->input->post('q');
        $field = $this->input->post('field');
        $data['query'] = $this->model_barang->search($q,$field);
        $this->load->view('barang/show', $data);
    }
    
    function cetakjalan() {
        $id = $this->uri->segment(3);
        $data['result'] = $this->model_barang->getBarang($id);

        if (empty($id) or count($data['result']) == 0) {
            redirect('admin/guru/index');
        } else {
            $result = $this->model_barang->getBarang($id);
            $data['id_order'] = $result['id_order'];
            $data['job_order'] = $result['job_order'];
            $data['no_sj'] = $result['no_sj'];
            $data['consgnee'] = $result['consgnee'];
            $data['origin'] = $result['origin'];
            $data['shipper'] = $result['shipper'];
            $data['via'] = $result['via'];
            $data['agent'] = $result['agent'];
            $data['ctn'] = $result['ctn'];
            $data['kg'] = $result['kg'];
            $data['m3'] = $result['m3'];
            $data['invoice'] = $result['invoice'];
            $data['description'] = $result['description'];
            $data['delivery'] = $result['delivery'];
            $data['penerimaan'] = $result['penerimaan'];
            $data['cost'] = $result['cost'];
            $data['profit'] = $result['profit'];
            $data['remarks'] = $result['remarks'];
            $this->load->view('barang/cetakjalan', $data);
        }
    }
    
    function search1(){
        $q = $this->input->post('q');
        $field = $this->input->post('field');
        $data['query'] = $this->model_barang->search($q,$field);
        $this->load->view('pengiriman/show', $data);
    }

}

?>